package fsu.cs.cis5930;

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

public class Settings {

	private SharedPreferences myPrefs;
	private SharedPreferences.Editor editor;

	/**
	 * These are the game settings. They are set in the Settings menu.
	 */
	enum Values
	{
		BOARD_MAX_X,				//Maximum X dimension of the game board.
		BOARD_MAX_Y,				//Maximum Y dimension of the game board.
		GAME_CONNECTION_TYPE,		//Type of connection used to communicate with other players.
		GAME_SPECIAL_BOMBS_ENABLED	//Are we using anything besides default bombs?
	}
	

	
	/**
	 * Set default settings.
	 */
	public Settings(Context context)
	{
		myPrefs = PreferenceManager.getDefaultSharedPreferences(context);
		editor = myPrefs.edit();
		
		setMaxX(3);
		setMaxY(4);
		setConnectionType(Connection.Type.SINGLE_PLAYER);
		setSpecialBombs(false);
	}
	
	//Mutators
	public void setMaxX(int x)
	{
		editor.putInt(Values.BOARD_MAX_X.name(), x);
		editor.commit();
	}
	
	public void setMaxY(int y)
	{
		editor.putInt(Values.BOARD_MAX_Y.name(), y);
		editor.commit();
	}
	
	public void setConnectionType(Connection.Type t)
	{
		editor.putInt(Values.GAME_CONNECTION_TYPE.name(), t.ordinal());
		editor.commit();
	}
	
	public void setSpecialBombs(Boolean b)
	{
		editor.putBoolean(Values.GAME_SPECIAL_BOMBS_ENABLED.name(), b);
		editor.commit();
	}
	
	
	//Accessors
	public int getMaxX()
	{
		return myPrefs.getInt(Values.BOARD_MAX_X.name(), 3);		
	}
	
	public int getMaxY()
	{
		return myPrefs.getInt(Values.BOARD_MAX_Y.name(), 4);		
	}
	
	public Connection.Type getConnectionType()
	{
		return Connection.Type.values()[myPrefs.getInt(Values.GAME_CONNECTION_TYPE.name(), Connection.Type.SINGLE_PLAYER.ordinal())];
	}
	
	public boolean getSpecialBombs()
	{
		return myPrefs.getBoolean(Values.GAME_SPECIAL_BOMBS_ENABLED.name(), false);
	}
	
	

	
}
